<?PHP $this->_extends('_layouts/manager_layout');?>
<?PHP $this->_block('head');?>

<?PHP $this->_endblock();?>
<?PHP $this->_block('contents');?>
<h2 class="aa1">我的商品</h2>

<form action="" method="post" id="form1">
<table class="ebay_table">
    <tr>
    <th width="120">
    	<b>商品编号</b>
    </th>
    <td width="250">
    	<input type="text" size="20" name="sn" value="<?php echo $url_args['sn'];?>" >
    </td>
    <th width="120">
    	<b>标题</b>
    </th>
    <td>
    	<input type="text" size="30" name="title" value="<?php echo $url_args['name'];?>" >
    </td>
    </tr>
    <tr>
    <th width="120">
    	<b>商品分类</b>
    </th>
    <td width="250">
		<select id='category_id' name='category_id' >
			<option value="">全部</option>
			<option value="0">未分类</option>
			<?php foreach($categories as $c):?>
				<?php if(count($c['children'])):?>
				<optgroup LABEL="<?=$c['name']?>"> 
					<?php foreach($c['children'] as $cc):?>
						<option value="<?=$cc['category_id']?>" ><?=$cc['name']?></option>
					<?php endforeach;?>
				</optgroup>
				<?php else:?>
				<option value="<?=$c['category_id']?>"><?=$c['name']?></option>
				<?php endif;?>
			<?php endforeach;?>
		</select>
		
    </td>
    <th width="120">
    	<b>标签</b>
    </th>
    <td>
	<div style=" display:inline">
		<?php /* if(count($Taggoods)): foreach($Taggoods as $tg):?>
    	<div ><input type="checkbox" name="tag_id[]" value="<?=$tg->tag_id?>"  /> <?=$tg->tag_name?> </div>
		<?php endforeach; endif; */?>
		<?php Q::control('dropdownlist','tag_id',array(
			'items'=> array('选择标签')+ Helper_Array::toHashMap($Taggoods->toArray(),'tag_id','tag_name'),
		 ))->display();?>
		
	</div>
    </td>
    </tr>

    <tr>
    <td></td>
    <td><input type="submit" class="anniu" value="确定搜索" onclick="">   &nbsp;&nbsp;  <input type="button" value=" clear " class="anniu" onclick="clearform()"> </td>
    <td></td>
    <td></td>
    </tr>
</table>
</form>
<?php if(isset($success)&&is_array($success)): ?>
	<div class="success">
		<?php foreach($success as $k=>$v):
			switch($k){
				case 'removegoods':
					if(count($v)) foreach($v as $id){
						echo '商品: '.$id.' , 删除成功 .<br>';
					}
				break;
		?>
			
		<?php } endforeach;?>
	</div>
	<?php	endif;?>
	<?php if(isset($error)&&is_array($error)):?>
	<div class="error">
		<?php  foreach($error as $k=>$v):
			switch($k){
				case 'removegoods':
					if(count($v)) foreach($v as $id){
						echo '商品: '.$id.' , 删除失败 .<br>';
					}
				break;
		?>
			
		<?php } endforeach;?>
	</div>
	<?php	endif;?>
<form action="" method="post" name="f1">
<table class="goods_table" style="text-align: center;" width="100%">
  <tr>
  	<th rowspan="2"></th>
	<th rowspan="2">图片</th>
    <th colspan="4">商品名</th>
    <th rowspan="2">操作</th>
  </tr>
  <tr>
	 <th>商品编号</th>
	 <th>类目</th>
	 <th>标签</th>
	 <th>售价</th> 
  </tr>
  <?php if (count($goods)):?>
  <?php foreach ($goods as $a):?>
  <tr>
  	<td rowspan="2"><input type="checkbox" name="goods_id[]" value="<?=$a->goods_id?>"  /></td>
  	<td rowspan="2">
    	<img src="<?php echo $a->imgurl ?>" width="38" height="38">
    </td>
    <td colspan="4">
    	<?php echo $a->title?>
    </td>
    <td rowspan="2">
        <a href="<?php echo url('storemanager/goodsedit',array('goods_id'=>$a->goods_id))?>">修改</a><br /><a href="" onclick="return confirm('确定删除吗 ?');">删除</a>
        
    </td>
  </tr>
  <tr>
	<td style="font-weight:bold">
		<?php echo $a->sn?>
	</td>
	<td>
    	<?php 
			if($a->category_id){
				$c=Category::find('category_id=?',$a->category_id)->getOne();
				echo $c->name;
			}
		?>
    </td>
	<td>
    	<?php 
		if(count($a->tag_ids)){foreach($a->tags as $tag){
			echo $tag->tag_name." , ";
		}}
		?>
    </td>
    <td>
    	<?php echo Helper_Currency::fetch($a->price,$a->currency);?>
    </td>
    
  </tr>
  <?php endforeach;?>
  <?php else:?>
  <tr>
	<td colspan="6">没有相关记录 </td>
  </tr>
  <?php endif;?>
</table>

<div>
	<input id="checkNegative2" type="checkbox" title='反选'>反,
	<a href="#" onclick="$('input[name^=goods_id]').attr('checked','checked');return false;">全选</a>

 	<select name="cmd" id="cmd" style="width:200px">
		<option value="">  选择你要做的操作 </option>
		<option value="batchmodify">批量修改</option>
		<option value="removegoods">  删除商品  </option>
	</select>  &nbsp;&nbsp;&nbsp;&nbsp;
		<input value="  Do it  " type="button"  onclick="docmd()" />
	</div>
</form>
<br />
<?php $this->_control('pagination2','collection-list',array('pagination'=>$pager,'url_args'=>$url_args)) ?>

<br>
<a href="<?php echo url('storemanager/goodsedit')?>" classs="anniu">添加商品</a><br><br>
</div>
<script language="javascript">
function docmd(){
	switch ($('#cmd').val()){
	case 'batchmodify':
		document.f1.action=('<?=url('/BatchModify')?>');
		break;
	default:
		document.f1.action='';
		break; 	
	}
	if(confirm('确定吗?')){
		document.f1.submit();
		return true;
	}else{
		return false;
	}
}
$('#checkNegative,#checkNegative2').click(function(){
	$('input[name^=goods_id]').each(function(){
		if($(this).attr('checked')){
			$(this).removeAttr('checked');
		}else{
			$(this).attr('checked','checked');
		}
	});
})
function clearform(){
	$('input[name=sn]').val('');
	$('input[name=title]').val('');
	$('select[name=category_id]').val('');
	$('select[name=tag_id]').val('');
}
</script>
<?PHP $this->_endblock();?>

